home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk122 / 3d / cube.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  5KB  |  146 lines

  1. /* Cube Demo Program - By Steve Ludtke */
  2. /*     cre : 1/3/90    mod : 3/11/90    */
  3. /*           Copyright 1990            */
  4.  
  5. /*
  6.           The 3d library and all associated software in this distribution
  7.           is Copyright 1990 by Steven J. Ludtke. You have permission to
  8.           use and/or modify this code for any purpose commercial or non-
  9.           commercial with two conditions : I must be given credit in any
  10.           distributed product's documentation, and if any part of this
  11.           package is used in any commercial product (even Shareware) one
  12.           free copy of said software must be sent to me at the following
  13.           address : Steven Ludtke, 406 Yale Cir., Glenwood Springs, CO
  14.           81601; all other royalties are waived. This Copyright notice
  15.           must accompany any distributions of any part of this package,
  16.           and in general, the package should be distributed intact, with
  17.           no modifications. This notice must not be removed from the 3d.c,
  18.           test.c, and cube.c source code in this release. Modified versions
  19.           may not be distributed without permission. If the conditions
  20.           in the disclaimer are not valid in your home state, permission
  21.           to use this software is revoked.
  22. */
  23.  
  24. /* This program works almost exactly like test.c with 2 exceptions. First,
  25. This program reads from a predefined string in memory instead of the
  26. keyboard. The moves are rather grainy, so the animation isn't very smooth
  27. looking. The other difference is double buffering. This program opens
  28. two screens, then alternates which one it draws on. (It always draws on
  29. the hidden one, then brings it up front.) In general, look at the comments
  30. in test.c for more info. */
  31.  
  32.  
  33. #include<stdio.h>
  34.  
  35. #define D3VDIST 256         /* distance to vanishing point */
  36. #define REZ     1024        /* calc resolution must be 2^x */
  37. #define REZB    7           /* number of bits in REZ */
  38. #define XCEN    320         /* center of bitmap X */
  39. #define YCEN    90          /* center of bitmap Y */
  40. #define XHI     639
  41. #define YHI     189
  42. #define XLO     0
  43. #define YLO     0
  44. #define ASPECT  22/10       /* aspect ratio */
  45. #include "3d.c"
  46.  
  47. #define NUMVEC 10
  48.  
  49. APTR IntuitionBase,GfxBase;
  50.  
  51. struct NewScreen NS = { 0,0,640,200,2,1,0,HIRES,CUSTOMSCREEN,NULL,"cube",NULL,
  52.     NULL };
  53.  
  54. long xxx[NUMVEC] = { 1, 1, 1, 1,-1,-1,-1,-1 };
  55. long yyy[NUMVEC] = { 1, 1,-1,-1, 1, 1,-1,-1 };
  56. long zzz[NUMVEC] = { 1,-1, 1,-1, 1,-1, 1,-1 };
  57.  
  58. LINES line[20] = { {0,1,0,0},{1,0,0,0},{5,0,0,0},{4,0,0,0},{0,0,0,0},
  59.     {0,1,0,0},{4,0,0,0},{6,0,0,0},{2,0,0,0},{0,0,0,0},
  60.     {2,1,0,0},{6,0,0,0},{7,0,0,0},{3,0,0,0},{2,0,0,0},
  61.     {7,1,0,0},{3,0,0,0},{1,0,0,0},{5,0,0,0},{7,0,0,0} };
  62.  
  63. char *todo = "8888888888888886kikikiki6666663339369666jjjjmmmm53333333333333333333333333335333333333333333333333333356666363636363636939969696966666666666666666666666666666666666333333333333333333333333333333333333ppppq";
  64. int pt = 0;
  65.  
  66. nextc()
  67. {
  68. return(todo[pt++]);
  69. }
  70.  
  71. main()
  72. {
  73. VECTOR v;
  74. double a1,a2,a3;
  75. char c;
  76. int i,p,q,r,f,crp;
  77. struct RastPort *rp[2];
  78. struct Screen *s1,*s2;
  79.  
  80. crp=f=0;
  81. GfxBase=(APTR) OpenLibrary("graphics.library",0);
  82. IntuitionBase=(APTR) OpenLibrary("intuition.library",0);
  83.  
  84. s1=(struct Screen *) OpenScreen(&NS);
  85. s2=(struct Screen *) OpenScreen(&NS);
  86. if (s1==NULL || s2==NULL) { printf("Can't open screen(s)\n"); exit(0); }
  87. rp[0]=&s1->RastPort;
  88. rp[1]=&s2->RastPort;
  89.  
  90. v.x=xxx;
  91. v.y=yyy;
  92. v.z=zzz;
  93. v.tx=(long *) malloc(NUMVEC*sizeof(long));
  94. v.ty=(long *) malloc(NUMVEC*sizeof(long));
  95. v.tz=(long *) malloc(NUMVEC*sizeof(long));
  96.  
  97. for(i=0; i<8; i++) { xxx[i]*=40; yyy[i]*=40; zzz[i]*=40; }
  98.  
  99. a1=a2=a3=0;
  100. p=q=r=0;
  101. Init3Ras(rp[0],rp[1],NULL,NULL);
  102. SetAPen(rp[0],1);
  103. SetOPen(rp[0],2);
  104. SetDrMd(rp[0],JAM1);
  105. SetAPen(rp[1],1);
  106. SetOPen(rp[1],2);
  107. SetDrMd(rp[1],JAM1);
  108.  
  109. while ((c=nextc())!='q') {
  110. switch(c) {
  111. case '9': a1+=PI/20; break;
  112. case '7': a1-=PI/20; break;
  113. case '6': a2+=PI/20; break;
  114. case '4': a2-=PI/20; break;
  115. case '3': a3+=PI/20; break;
  116. case '1': a3-=PI/20; break;
  117. case '5': f^=1;      break;
  118. case 'k': q+=5;      break;
  119. case 'j': q-=5;      break;
  120. case 'm': r+=5;      break;
  121. case 'i': r-=5;      break;
  122. case '8': p+=10;     break;
  123. case '2': p-=10;     break;
  124. case 'p': for (i=0; i<30; i++) WaitTOF(); break;
  125. }
  126. setxfm(a1,a2,a3,q,p,r,1,1);
  127. rotatev(&v,8);
  128. SetRast(rp[crp],0);
  129. if (f==0) d3lines(&v,line,20,rp[crp]);
  130. else d3surf(&v,line,20,rp[crp]);
  131. if (crp==1) ScreenToFront(s2);
  132. else ScreenToFront(s1);
  133. crp^=1;
  134. }
  135.  
  136. Exit3d(rp[0]);
  137. CloseScreen(s1);
  138. CloseScreen(s2);
  139. free(v.tx);
  140. free(v.ty);
  141. free(v.tz);
  142. _exit(0);
  143. }
  144.  
  145.  
  146.